import api from '../../../fetch/api'

export default {
    data() {
        return {
            dialogVisibleForEmergency: false, //是否显示告警设置框
            cardNoIn: false, //白名单进场告警开关
            cardNoOut: false, //白名单离场告警开关
            pos_cardNoIn: false, //白名单进场告警开关-pos机
            pos_cardNoOut: false, //白名单离场告警开关-pos机
            emergencySetupId: '', //告警设置id
        }
    },
    created() {
        this.getParkRedlistRule();
    },
    beforeDestroy() {
    },
    filters: {
        syncStatusShow: function (value) {
            if (value == 0) {
                return "未同步";
            } else if (value == 1) {
                return "同步中";
            } else if (value == 2) {
                return "成功";
            } else if (value == 3) {
                return "失败";
            } else {
                return "未定义";
            }
        },
        buttonShow: function(){

        }
    },
    methods: {
        //打开告警设置框
        openEmergencySetup(){
            let self = this
            API.fetchGet('park/emergency/config/getRedlist.do',{}).then(res=>{
                let data = res.data
                self.emergencySetupId = data.id
                self.cardNoIn = data.redlistIn
                self.cardNoOut = data.redlistOut
                self.pos_cardNoIn = data.lmRedlistIn
                self.pos_cardNoOut = data.lmRedlistOut
            },err=>{})
            this.dialogVisibleForEmergency = true
        },
        //保存告警设置
        saveEmergencySetup(){
            let self = this
            let params = {};
            params.id = self.emergencySetupId
            params.redlistIn = self.cardNoIn==null ? false : self.cardNoIn
            params.redlistOut = self.cardNoOut==null ? false : self.cardNoOut
            params.lmRedlistIn = self.pos_cardNoIn==null ? false : self.pos_cardNoIn
            params.lmRedlistOut = self.pos_cardNoOut==null ? false : self.pos_cardNoOut
            API.fetchPost('park/emergency/config/updateRedlist.do',params).then(res=>{
            // console.log('res:',res)
            self.dialogVisibleForEmergency = false
            },err=>{})
        },
        getParkRedlistRule(){//获取规则
            let self = this;
            API.park.GetParkRedlistRuleData().then(res => {
                let data = res.data;
                self.ruleItems = data;
          }, err => {});
        },
        openGateLog() {
            //按钮详情弹框
            let self = this;
            var params = {
                page: this.synchronismModalData.pageNumber,
                rp: this.synchronismModalData.pageSize
            };

            API.park.GetSyncDetailData(params).then(res =>{
                 let data = res.data,
                        list = data.rows;
                    self.synchronismModalData.tbodysInfo = list;
                    self.synchronismModalData.total = data.total;
                    self.toOpenModal('synchronismModal');
                },err =>{});
        },
        getPicPagination(curPage, pageSize) {
            this.picModalData.pageNumber = curPage;
            this.picModalData.pageSize = pageSize ? pageSize : this.picModalData.pageSize;
            this.photoLog();
        },
        getSwitchPagination(curPage, pageSize) {
            this.synchronismModalData.pageNumber = curPage;
            this.synchronismModalData.pageSize = pageSize ? pageSize : this.synchronismModalData.pageSize;
            this.openGateLog();
        },
        _delete(index,item) {
            //console.log(index)
            //this.ruleItems.splice(index, 1);
            let self = this;
            this.showDialog("是否确认删除该规则？",[],function(){
                let params = {id:item.id};
                API.park.DelParkRedlistRuleData(params).then(res =>{
                    self.getParkRedlistRule();
                },err =>{});

            },"温馨提示",function(){
                //取消时不操作
            });
        },
        _add() {
            let self = this;
            if (self.ruleValue && self.ruleValue.trim()) {
                let _ruleValue = self.ruleValue.trim(),
                param = {};
                param.redlistParam = _ruleValue;
                API.park.AddParkRedlistRuleData(param).then(res =>{
                    self.ruleValue='';
                    self.getParkRedlistRule();
                },err =>{});
            }
        },
        syncAll(){
            let self = this;
            this.showDialog("是否确认同步规则到线下停车场？",[],function(){
                let params = {};
                API.park.SyncParkRedlistRuleData(params).then(res =>{
                    if(res.status==1){
                        self.showToast('操作成功！', 1);
                    }
                },err =>{});
            },"温馨提示",function(){
                //取消时不操作
            });
        },
        sync(row){
            let self = this;
            this.showDialog("是否确认同步规则到线下停车场？",[],function(){
                let params = {id:row.id};
                API.park.ResyncParkRedlistRuleData(params).then(res =>{
                    self.openGateLog();
                },err =>{});
            },"温馨提示",function(){
                //取消时不操作
            });
        }
    }
}